<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD H TML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>My JSP 'map.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <script src="OpenLayers2/OpenLayers.js"></script>
    <style type="text/css">

    </style>
</head>

<body>
<div id="markers" style="width:100%;height:100%;"></div>

<script type="text/javascript">
    var map = new OpenLayers.Map("markers");
    layer = new OpenLayers.Layer.OSM("Map");
    map.addLayer(layer);
    map.setCenter(new OpenLayers.LonLat(114, 30), 8);
    map.addControl(new OpenLayers.Control.LayerSwitcher());

    var pointFeatures = [];
    var MonitArr = [];

    /*
     var lonlat = new OpenLayers.LonLat(114,30);
     lonlat.transform(new OpenLayers.Projection("EPSG:4326"),new OpenLayers.Projection("EPSG:900913"));
     var pointGeometry = new OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat);
     var pointFeature = new OpenLayers.Feature.Vector(pointGeometry);
     pointFeatures.push(pointFeature);
     pointLayer.addFeatures(pointFeatures);
     */
    var markers = new OpenLayers.Layer.Markers("Markers");
    var MonitArr = [];
    $.ajax({
        type: "get",
        async: true,
        url: "QueryMonitSite.action",
        success: function (result) {
            if (result == "error") {
                alert("后台无数据，您可添加数据");
                var nullTree = [];
                createTree(nullTree);
                return;
            } else if (result == "NO Right!") {
                alert("你没有权利操作监测点！");
                return;
            }


            var MonitArr = result.split(',');
            for (var i = 0; i < MonitArr.length; i++) {

                $.ajax({
                    type: "get",
                    url: "ShowMessage.action?monitID=" + MonitArr[i],
                    async: true,
                    success: function (result) {
                        MonitArrCon = result.split(',');
                        var px = MonitArrCon[9];
                        var py = MonitArrCon[10];

                        /*添加marker*/
                        var locat = new OpenLayers.LonLat(px, py);
                        //转换坐标系
                        locat.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));

                        //mark图标
                        var size = new OpenLayers.Size(25, 25);
                        var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
                        var icon = new OpenLayers.Icon('marker.png', size, offset);
                        var marker = new OpenLayers.Marker(locat, icon);
                        markers.addMarker(marker);

                        //单击显示信息
                        var content = "<div><strong>Institution:</strong>" + MonitArrCon[1] +
                            "</br><strong>Investigator:</strong>" + MonitArrCon[2] +
                            "</br><strong>InvestigationDate:</strong>" + "</br>" + MonitArrCon[3]
                        "</div>";
                        marker.events.register("mousedown", marker, function (feature) {
                            popup = new OpenLayers.Popup("click",
                                locat,
                                new OpenLayers.Size(150, 80),
                                content
                            );
                            popup.closeOnMove = true;
                            map.addPopup(popup);
                        });
                        marker.events.register("mouseover", marker, function () {
                            popup = new OpenLayers.Popup("click",
                                locat,
                                new OpenLayers.Size(150, 80),
                                content
                            );
                            popup.closeOnMove = true;
                            map.addPopup(popup);
                        });
                        marker.events.register("mouseout", marker, function () {

                            map.removePopup(popup);

                        });

                        map.setCenter(locat);
                        map.addLayer(markers);
                        map.addControl(new OpenLayers.Control.MousePosition());
                    }
                });

            }
            return true;

        }
    });


</script>

</body>
</html>
